//
//  ThreeViewController.m
//  WuliHanhan
//
//  Created by chen tang on 16/2/25.
//  Copyright © 2016年 LVpeng. All rights reserved.
//

#import "ThreeViewController.h"
#import "Header.h"


#import "CameraViewController.h"
#import "PhotoSelectViewController.h"
#import "BoxDownLoadViewController.h"


#import "FMDB.h"




#import "DataBaseSaveEditeImageModel.h"


#define KX          WithView/3.0
#define textPX      119.0/WithView

@interface ThreeViewController ()<cameraDeledate, UIScrollViewDelegate>
{
    UIView *bottomView;
    UIButton *button1;
    UIButton *button2;
    UIButton *button3;
    
    float currentX;
}


@property (nonatomic, strong) UIViewController *currentVC;
@property (nonatomic, strong) UIScrollView *mainScrollview;

@end





@implementation ThreeViewController



sloganIntence(ThreeViewController)







- (void)loadView
{
    [super loadView];
    
    
    
    
    self.automaticallyAdjustsScrollViewInsets = false;
    
    [self.view setBackgroundColor:[UIColor blackColor]];
    
    [self.navigationController setNavigationBarHidden:YES];
    
    
    _mainScrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WithView, heightView-20.0)];
    [self.view addSubview:_mainScrollview];
    [_mainScrollview setPagingEnabled:YES];
    [_mainScrollview setContentSize:CGSizeMake(WithView*3, heightView-20.0)];
    
    
    button1 = [[UIButton alloc] initWithFrame:CGRectMake(0, heightView-48, KX, 48)];
    [button1 setBackgroundColor:[UIColor whiteColor]];
    [button1 setTitleColor:uicolor(34, 34, 34) forState:UIControlStateNormal];
    [button1 setTitle:@"照片" forState:UIControlStateNormal];
    [button1.titleLabel setFont:[UIFont systemFontOfSize:16.0]];
//    [button1.titleLabel setTransform:CGAffineTransformMakeScale(2.0, 2.0)];
    [self.view addSubview:button1];
//
    button2 = [[UIButton alloc] initWithFrame:CGRectMake(KX, heightView-48, KX, 48)];
    [button2 setBackgroundColor:[UIColor whiteColor]];
    [button2 setTitleColor:uicolor(153, 153, 153) forState:UIControlStateNormal];
    [button2 setTitle:@"收藏" forState:UIControlStateNormal];
    [button2.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
    [self.view addSubview:button2];
//
    button3 = [UIButton buttonWithType:UIButtonTypeCustom];
    [button3 setFrame:CGRectMake(KX*2, heightView-48, WithView/3.0, 48)];
    [button3 setBackgroundColor:[UIColor whiteColor]];
    [button3 setTitleColor:uicolor(153, 153, 153) forState:UIControlStateNormal];
    [button3 setTitle:@"拍照" forState:UIControlStateNormal];
    [button3.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
    [self.view addSubview:button3];

    
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, heightView-48.5, WithView, 0.5f)];
    [lineView setBackgroundColor:uicolor(204, 204, 204)];
    [self.view addSubview:lineView];
    
    
    PhotoSelectViewController *cameraView = [[PhotoSelectViewController alloc] init];
    [cameraView setPlusImage:_plusImage];
    [cameraView.view setFrame:CGRectMake(0, 0, WithView, heightView-40)];
    [_mainScrollview addSubview:cameraView.view];
    [self addChildViewController:cameraView];
//
    self.currentVC = cameraView;
    
    
    BoxDownLoadViewController *boxDownView = [[BoxDownLoadViewController alloc] init];
    [boxDownView.view setFrame:CGRectMake(WithView, 0, WithView, heightView-20)];
    [_mainScrollview addSubview:boxDownView.view];
    [self addChildViewController:boxDownView];
    
//    CameraViewController *camera = [[CameraViewController alloc] init];
//    [camera setMcameraDeledate:self];
//    [camera.view setFrame:CGRectMake(WithView*2, 0, WithView, heightView-20)];
    
//    [_mainScrollview addSubview:camera.view];
//    [self addChildViewController:camera];
    
    
    
    bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, heightView-2.5, WithView/3.0, 2.5)];
    [bottomView setBackgroundColor:uicolor(255, 204, 0)];
    [self.view addSubview:bottomView];
    
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [_mainScrollview setBounces:NO];
    [_mainScrollview setDelegate:self];
    

}



- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
}


- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    float i = scrollView.contentOffset.x;
    [bottomView setFrame:CGRectMake(i*(1.0/3.0), heightView-2.5, WithView/3.0, 2.5)];
    
    NSLog(@"%f", i);
    
//    float colortext = 153.0-textPX*ABS(i-currentX);
//    float colorFord = 34.0+textPX*ABS(i-currentX);
//    
//    
////    NSLog(@"%f", colortext);
//    
//    if (i >=0 && i < WithView)
//    {
//        [button1 setTitleColor:uicolor(colortext, colortext, colortext) forState:UIControlStateNormal];
//        [button2 setTitleColor:uicolor(colorFord, colorFord, colorFord) forState:UIControlStateNormal];
//        [button3 setTitleColor:uicolor(colorFord, colorFord, colorFord) forState:UIControlStateNormal];
//    }
//    else if (i >= WithView && i < WithView*2)
//    {
//        [button2 setTitleColor:uicolor(colortext, colortext, colortext) forState:UIControlStateNormal];
//        [button1 setTitleColor:uicolor(colorFord, colorFord, colorFord) forState:UIControlStateNormal];
//        [button3 setTitleColor:uicolor(colorFord, colorFord, colorFord) forState:UIControlStateNormal];
//    }
//    else if (i <= WithView*2)
//    {
//        [button3 setTitleColor:uicolor(colortext, colortext, colortext) forState:UIControlStateNormal];
//        [button2 setTitleColor:uicolor(colorFord, colorFord, colorFord) forState:UIControlStateNormal];
//        [button1 setTitleColor:uicolor(colorFord, colorFord, colorFord) forState:UIControlStateNormal];
//    }
    
    if (i/WithView == 0.0)
    {
        [button1 setTitleColor:uicolor(34, 34, 34) forState:UIControlStateNormal];
        [button1.titleLabel setFont:[UIFont systemFontOfSize:16.0]];
        
        [button2 setTitleColor:uicolor(153, 153, 153) forState:UIControlStateNormal];
        [button2.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
        
        [button3 setTitleColor:uicolor(153, 153, 153) forState:UIControlStateNormal];
        [button3.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
        
    }
    else if (i/WithView == 1.0)
    {
        [button2 setTitleColor:uicolor(34, 34, 34) forState:UIControlStateNormal];
        [button2.titleLabel setFont:[UIFont systemFontOfSize:16.0]];
        
        [button1 setTitleColor:uicolor(153, 153, 153) forState:UIControlStateNormal];
        [button1.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
        
        [button3 setTitleColor:uicolor(153, 153, 153) forState:UIControlStateNormal];
        [button3.titleLabel setFont:[UIFont systemFontOfSize:15.0]];

    }
    else if (i/WithView == 2.0)
    {
        [button3 setTitleColor:uicolor(34, 34, 34) forState:UIControlStateNormal];
        [button3.titleLabel setFont:[UIFont systemFontOfSize:16.0]];
        
        [button2 setTitleColor:uicolor(153, 153, 153) forState:UIControlStateNormal];
        [button2.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
        
        [button1 setTitleColor:uicolor(153, 153, 153) forState:UIControlStateNormal];
        [button1.titleLabel setFont:[UIFont systemFontOfSize:15.0]];

    }
    
}




- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    currentX = scrollView.contentOffset.x;
//    NSLog(@"%f", currentX);
}


- (void)buttonPressPush
{
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
